import java.util.LinkedList;
import java.util.Queue;

public class Test {
    public static void main(String[] args) {
        System.out.println(  yuSeFu(10,3));
    }


    public static int  yuSeFu(int max,int offset) {

        Queue<Integer> queue = new LinkedList<>();
        for (int i = 0; i < max; i++) {
            queue.add(i + 1);
        }
        int counts = 0;
        while (!queue.isEmpty()) {

            Integer person = queue.poll();
            counts++;
            if (counts % offset == 0) {
                if (queue.isEmpty()){
                    return person;
                }
            } else {
                queue.add(person);
            }

        }
        return 0;
    }
}
